<div class="row spacing-bottom 2col">   
    <div class="col-md-3 col-sm-6 spacing-bottom-sm">   
        <div class="tiles green added-margin">
          <div class="tiles-body">
                <div class="tiles-title">
                    用户总数
                </div>  
                <div class="heading">
                    <span><?= $total ?></span>位
                </div>             
                <div class="description">
                    <h4 class="mini-description ">
                        <i class="icon-plus-sign"></i>&nbsp;
                        <a class="white" href="javascript:void(0)" onclick="$.Admin.add()">新增一个用户</a>
                    </h4>
                </div>
            </div>  
        </div>
    </div>              
</div>

<div class="row">
    <div class="col-md-12">
      <div class="grid simple">
        <div class="grid-title no-border">
            <h4>用户 <span class="semi-bold">查询</span></h4>
            <div class="tools"> 
                <a class="collapse" href="javascript:;"></a>
            </div>
        </div>
        <div class="grid-body no-border">
            <form class="form-no-horizontal-spacing" method="GET" action="<?= DOMAIN.'admin/browse' ?>">
                <div class="row column-seperation">
                    <div class="col-md-4">
                        <div class="form-group col-md-12">
                            <label class="form-label">用户名</label>
                            <input type="text" class="form-control" name="username" value="<?= $default['username'] ?>">
                        </div>
                        <div class="form-group col-md-12">
                            <label class="form-label">昵称</label>
                            <input type="text" class="form-control" name="nickname" value="<?= $default['nickname'] ?>">
                        </div>
                        <div class="form-group col-md-12">
                            <label class="form-label">性别</label>
                            <div class="radio radio-control">
                                <input type="radio" checked="checked" id="gender-ALL" name="gender" value="">
                                <label for="gender-ALL">不限</label>
                                <? foreach($admin_gender as $k => $v): ?>
                                    <? if($default['gender'] == $k): ?>
                                        <input type="radio" checked="checked" value="<?= $k ?>" name="gender" id="<?= "gender-{$k}" ?>">
                                    <? else: ?>
                                        <input type="radio" value="<?= $k ?>" name="gender" id="<?= "gender-{$k}" ?>">
                                    <? endif ?>
                                    <label for="<?= "gender-{$k}" ?>"><?= $v ?></label>
                                <? endforeach ?>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-4">
                        <div class="form-group col-md-12">
                            <label class="form-label">状态</label>
                            <div class="radio radio-control">
                                <input type="radio" checked="checked" id="status-ALL" name="status" value="">
                                <label for="status-ALL">不限</label>
                                <? foreach($admin_status as $k => $v): ?>
                                    <? if($default['status'] == $k): ?>
                                        <input type="radio" checked="checked" value="<?= $k ?>" name="status" id="<?= "status-{$k}" ?>">
                                    <? else: ?>
                                        <input type="radio" value="<?= $k ?>" name="status" id="<?= "status-{$k}" ?>">
                                    <? endif ?>
                                    <label for="<?= "status-{$k}" ?>"><?= $v ?></label>
                                <? endforeach ?>
                            </div>
                        </div>
                        <div class="form-group col-md-12">
                            <label class="form-label">角色</label>
                            <select name="role" class="select2 form-control">
                                <option value="0" selected="selected">不限</option>
                                <? foreach($admin_role as $v): ?>
                                    <option value="<?= $v['role_id'] ?>" <?= ($default['role'] == $v['role_id'] ) ? 'selected="selected"' : "" ?>>
                                        <?= $v['name'] ?>
                                    </option>
                                <? endforeach ?>
                            </select>
                        </div>
                    </div>

                    <div class="col-md-4">
                        <div class="form-group col-md-12">
                            <label class="form-label">创建时间</label><br>
                            <input type="text" name="create_time_start" value="<?= $default['create_time_start'] ?>" class="datepicker form-inline col-md-5">
                            <div class="form-inline col-md-2"> ~ </div>
                            <input type="text" name="create_time_end" value="<?= $default['create_time_end'] ?>"class="datepicker form-inline col-md-5">
                        </div><br><br>
                        <div class="form-group col-md-12">
                            <label class="form-label">更新时间</label><br>
                            <input type="text" name="update_time_start" value="<?= $default['update_time_start'] ?>"class="datepicker form-inline col-md-5">
                            <div class="form-inline col-md-2"> ~ </div>
                            <input type="text" name="update_time_end" value="<?= $default['update_time_end'] ?>"class="datepicker form-inline col-md-5">
                        </div>
                    </div>
                </div>

                <div class="form-actions">
                    <div class="pull-left">
                      <button type="submit" class="btn btn-warning btn-cons"><i class="icon-search"></i>&nbsp;查询</button>
                      <button type="button" class="btn btn-white btn-cons" onclick="$.T.reset_form(this)">重置</button>
                    </div>
                </div>
            </form>
        </div>
      </div>
    </div>
</div>

<? if($list): ?>
    <div class="row-fluid">
        <div class="grid simple">
            <div class="grid-title no-border">
            </div>
            <div class="grid-body no-border">
                <? if($list['data']): ?>
                <table id="data-table" class="table table-striped">
                    <colgroup>
                        <col width="">
                        <col width="">
                        <col width="">
                        <col width="20%">
                        <col width="">
                        <col width="">
                        <col width="">
                    </colgroup>
                    <thead>
                        <tr>
                            <th>状态</th>
                            <th>用户名</th>
                            <th>昵称</th>
                            <th>角色</th>
                            <th>性别</th>
                            <th>上次登录</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <? foreach($list['data'] as $item): ?>
                        <tr>
                            <td>
                                <span class="label <?= $item['status'] == ADMIN_STATUS_OFF ? 'label-important' : '' ?>">
                                    <?= $admin_status[$item['status']] ?>
                                </span>
                            </td>
                            <td><?= $item['username'] ?></td>
                            <td><?= $item['nickname'] ?></td>
                            <td>
                                <? if($item['roles_info']): ?>
                                    <? foreach($item['roles_info'] as $r): ?>
                                        <?= $r['name'] ?>,
                                    <? endforeach ?>
                                <? endif ?>
                            </td>

                            <td><span class="muted"><?= $admin_gender[$item['gender']] ?></span></td>
                            <td><span class="muted"><?= time_format($item['last_login']) ?></span></td>
                            <td>
                                <? if($item['status'] == ADMIN_STATUS_OFF): ?>
                                    <a href="javascript:void(0)" onclick="$.Admin.change_status('<?= $item['admin_id']?>', 'on');" >
                                        <i class="icon-rocket"></i>
                                        启用
                                    </a>
                                <? else: ?>
                                    <a href="javascript:void(0)" onclick="$.Admin.change_status('<?= $item['admin_id']?>', 'off');" >
                                        <i class="icon-ban-circle"></i>
                                        停用
                                    </a>
                                    &nbsp;
                                    <a href="javascript:void(0)" onclick="$.Admin.view('<?= $item['admin_id'] ?>')">
                                        <i class="icon-desktop"></i>
                                        查看
                                    </a>
                                    &nbsp;
                                    <a href="javascript:void(0)" onclick="$.Admin.edit_role('<?= $item['admin_id'] ?>')">
                                        <i class="icon-user-md"></i>
                                        角色
                                    </a>
                                <? endif ?>

                            </td>
                        </tr>
                        <? endforeach ?>
                    </tbody>
                    <tfoot>
                        <tr>
                            <td colspan="7">
                                每页
                                <select class="select2 pagesize">
                                    <? foreach($pagesize as $k => $v): ?>
                                        <option value="<?= $k ?>" <?= $k == $list['size'] ? 'selected="selected"' : '' ?>><?= $v ?></option>
                                    <? endforeach ?>
                                </select>
                                <?= $pagination ?>
                                <div class="pagination_info">
                                    总计：<?= $list['total'] ?>
                                </div>
                            </td>
                        </tr>
                    </tfoot>
                </table>
                <? else: ?>
                    <h4 class="text-success"><i class="icon-meh"></i> &nbsp;很抱歉，没有找到符合条件的记录。</hr>
                <? endif ?>
            </div>
        </div>
    </div>
<? endif ?>
<script type="text/javascript">
    $(document).ready(function(){
        $('.datepicker').datepicker();
    });

    $.Admin = {
        /**
         * [查看]
         */
        view: function(id)
        {
            var id  = $.T.to_int(id);
            var opt = {width: 800,height:700, lock: true, opacity: 0.75, title: '<h3>查看 <span class="semi-bold">用户</span></h3>'}; 
            $.dialog.open($.G.domain+'admin/view/'+id, opt, false)
        },

        /**
         * [新增]
         */
        add: function()
        {
            var opt = {width: 800,height:700, lock: true, opacity: 0.75, title: '<h3>新增 <span class="semi-bold">用户</span></h3>',  close: function(){$.T.refresh()}}; 
            $.dialog.open($.G.domain+'admin/add', opt, false)
        },

        /**
         * [编辑角色]
         */
        edit_role: function(id)
        {
            var id  = $.T.to_int(id);
            var opt = {width: 800,height:700, lock: true, opacity: 0.75, title: '<h3>编辑 <span class="semi-bold">用户角色</span></h3>',  close: function(){$.T.refresh()}}; 
            $.dialog.open($.G.domain+'admin/edit_role/'+id, opt, false)
        },

        /**
         * [改变状态]
         */
        change_status: function(id, act)
        {
            var id = $.T.to_int(id);
            if( id <= 0)
            {
                $.T.alert("修改用户状态失败：没有提供用户id。");
                return false;
            }
            if( $.T.empty(act) )
            {
                $.T.alert("修改用户状态失败：没有提供操作类型。");
                return false;
            }
            $.T.confirm('确认要执行这个操作么？', function(){
                $.getJSON($.G.domain+"admin/change_status/"+id+"/?act="+act+"&is_ajax=1", function(response)
                {
                    if( false == response.status)
                    {
                        $.T.alert(response.msg);
                    }
                    else
                    {
                        $.T.refresh();
                    }
                });
            });
        }
    }
</script>